﻿using System;

namespace Lesson12_练习题
{
    class Program
    {
        #region 练习一
        //使用结构体描述学生的信息：姓名 性别 年龄 班级 专业
        //创建两个学员对象，并对其基本信息进行初始化并打印
        struct Student
        {
            public string name;
            public bool sex;
            public int age;
            public int clas;
            public string major;

            public Student(string name,  bool sex, int age, int clas, string major)
            {
                this.name = name;
                this.sex = sex;
                this.age = age;
                this.clas = clas;
                this.major = major;
            }

            public void PrintInfo()
            {
                Console.WriteLine("姓名:{0} 性别:{1} 年龄:{2} 班级:{3} 专业:{4}", name, sex ? "男" : "女", age, clas, major);
            }
        }
        #endregion

        #region 练习二
        //使用结构体描述一个矩形的信息
        //初始化矩形信息 打印矩形的长 宽 面积 周长
        struct Rect
        {
            public int length;
            public int width;

            public Rect(int length, int width)
            {
                this.length = length;
                this.width = width;
            }

            public void PrintInfo()
            {
                Console.WriteLine("矩形的长{0} 宽{1} 面积{2} 周长{3}", length, width, length * width, 2 * (length + width));
            }
        }
        #endregion

        #region 练习三
        //使用结构体描述玩家信息：姓名，职业
        //请用户输入姓名，选择职业，最后打印玩家的攻击信息
        //职业：
        //猎人（技能：假死）
        //战士（技能：冲锋）
        //法师（技能：奥术冲击）
        struct Player
        {
            public string name;
            public E_Occupation occupation;

            public Player(string name, E_Occupation occupation)
            {
                this.name = name;
                this.occupation = occupation;
            }

            public void PrintInfo(string name, E_Occupation occupation)
            {
                string occupationName = "";
                string skill = "";
                switch (occupation)
                {
                    case E_Occupation.Hunter:
                        occupationName = "猎人";
                        skill = "假死";
                        break;
                    case E_Occupation.Warrior:
                        occupationName = "战士";
                        skill = "冲锋";
                        break;
                    case E_Occupation.Master:
                        occupationName = "法师";
                        skill = "奥术冲击";
                        break;
                    default:
                        break;
                }
                Console.WriteLine("{0}{1}释放了{2}", occupationName, name, skill);
            }
        }
        //申明一个枚举用于存放技能信息
        enum E_Occupation
        {
            Hunter = 1,
            Warrior,
            Master,
        }
        #endregion

        #region 练习四
        //实现英雄与Boss战斗
        struct Hero
        {
            public string name;
            public int atk;
            public int def;
            public int hp;

            public Hero(string name, int atk, int def, int hp)
            {
                this.name = name;
                this.atk = atk;
                this.def = def;
                this.hp = hp;
            }

            public void Atk(ref Boss boss)
            {
                //Boss属性属于外部成员，需传入参数
                //英雄属性属于内部成员，无需传入参数
                boss.hp -= atk - boss.def;
                Console.WriteLine("{0}攻击了{1}，造成了{2}点伤害，{3}剩余{4}点血量", name, boss.name, atk - boss.def, boss.name, boss.hp);
            }
        }

        struct Boss
        {
            public string name;
            public int atk;
            public int def;
            public int hp;

            public Boss(string name, int atk, int def, int hp)
            {
                this.name = name;
                this.atk = atk;
                this.def = def;
                this.hp = hp;
            }

            public void Atk(ref Hero hero)
            {
                //Boss属性属于外部成员，需传入参数
                //英雄属性属于内部成员，无需传入参数
                hero.hp -= atk - hero.def;
                Console.WriteLine("{0}攻击了{1}，造成了{2}点伤害，{3}剩余{4}点血量", name, hero.name, atk - hero.def, hero.name, hero.hp);
            }
        }
        #endregion

        static void Main(string[] args)
        {
            #region 练习一
            Student stu1 = new Student("小明", true, 18, 2, "土木工程");
            stu1.PrintInfo();
            Student stu2 = new Student("小红", false, 17, 3, "软件工程");
            stu2.PrintInfo();
            #endregion

            #region 练习二
            Rect rect = new Rect(3, 4);
            rect.PrintInfo();
            #endregion

            #region 练习三
            Console.WriteLine("请输入玩家姓名");
            string name = Console.ReadLine();
            Console.WriteLine("请输入玩家职业（1.猎人 2.战士 3.法师）");
            try
            {
                E_Occupation occupation = (E_Occupation)int.Parse(Console.ReadLine());
                //调用构造函数初始化
                Player player = new Player(name, occupation);
                player.PrintInfo(name, occupation);
            }
            catch
            {
                Console.WriteLine("请输入数字");
            }
            #endregion

            #region 练习四
            Hero hero = new Hero("LiberTy", 10, 5, 100);
            Boss boss = new Boss("boss", 9, 4, 100);
            while (true)
            {
                hero.Atk(ref boss);
                if(boss.hp <= 0)
                {
                    Console.WriteLine("战斗结束");
                    break;
                }
                boss.Atk(ref hero);
                if (hero.hp <= 0)
                {
                    Console.WriteLine("战斗结束");
                    break;
                }
                Console.WriteLine();
                Console.WriteLine("按任意键继续");
                Console.ReadKey(true);
                Console.Clear();
            }
            #endregion

        }
    }
}